/**
 * @author BINGENGQI
 * checkbox and datagrid.js
 */

$("document").ready(function(){
    $('#pp').portal({
        border : false,
        fit : true
    });
    $(":checkbox").attr("checked",true);
    $(":checkbox").click(function(){
        var panelId = $(this).attr("cor");
        if(this.checked){
            $("#" + panelId).panel('open');
        }else{
            $("#" + panelId).panel('close');
        }
            
                });//set checkbox default as checked
                //if checkbox is unchecked, then panel should be closed
                //Configure Home
                $("#btnConfgHome").click(
                    function(){
                        $('#dlg_config_home').dialog('open');
                    }  
                );
                //timer count down
                $("#countdown_dashboard").countDown({
                    targetOffset: {
                        'min':      30,
                        'sec':      0
                    }, 
                    onComplete: function() { 
                        alert("Time Out! Please login again!");
                        //remove();
                    }
                });
                 //slider
	            $("#move-animate-left").tabso({
	                cntSelect:"#leftcon",
	                tabEvent:"mouseover",
	                tabStyle:"move-animate",
	                direction : "left"
	            });
	            
	            $("#refresh").click(function(){
	            	location.reload();
	            });
	            
	           $("#helplink").click(function(){
	           	    $("#tutorial").show();	           
	           	 });
	           	 
	           	$("#closeTutorialLbl").click(function(){
	           		$("#tutorial").hide();
	           	});  	 
            });
            /*
            function remove() {
                $('#pp').portal('remove', $('#pgrid'));
                $('#pp').portal('resize');
            }
            */
            function demo(val){
            	var pId = $(val).attr("id");
            	//alert(pId);
            	if(pId=="pgrid"){
            		//alert("testing or not");
            		var cekBox = $("input[cor='pgrid']");
            		$(cekBox).attr("checked",false);
            	}else if(pId=="pnlANA"){
            		var cekBox = $("input[cor='pnlANA']");
                    $(cekBox).attr("checked",false);
            	}else if(pId=="pnlSdSmy"){
                    var cekBox = $("input[cor='pnlSdSmy']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="policySv"){
                    var cekBox = $("input[cor='policySv']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlTopAirCrs"){
                    var cekBox = $("input[cor='pnlTopAirCrs']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlAirSpd"){
                    var cekBox = $("input[cor='pnlAirSpd']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts"){
                    var cekBox = $("input[cor='pnlPlySts']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts1"){
                    var cekBox = $("input[cor='pnlPlySts1']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts2"){
                    var cekBox = $("input[cor='pnlPlySts2']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts3"){
                    var cekBox = $("input[cor='pnlPlySts3']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts4"){
                    var cekBox = $("input[cor='pnlPlySts4']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts5"){
                    var cekBox = $("input[cor='pnlPlySts5']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts6"){
                    var cekBox = $("input[cor='pnlPlySts6']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts7"){
                    var cekBox = $("input[cor='pnlPlySts7']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts8"){
                    var cekBox = $("input[cor='pnlPlySts8']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts9"){
                    var cekBox = $("input[cor='pnlPlySts9']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts10"){
                    var cekBox = $("input[cor='pnlPlySts10']");
                    $(cekBox).attr("checked",false);
                }else if(pId=="pnlPlySts11"){
                    var cekBox = $("input[cor='pnlPlySts11']");
                    $(cekBox).attr("checked",false);
                }
                
            }
            function formatPrice(val,row){
            if (val < 30){
                return '<div style="margin-left:18px;margin-top:2px; float:left;color:red;">'+val+'%</div><div style="margin-left: 6px;margin-top:6px; border:#f15b6c solid 1px; width:6px;height:6px; float:left;border-radius:3px; background-color:red;" class="easyui-tooltip" title="value<30%"></div>';
	            } 
	            else if(val>30 && val<70){
	                return '<div style="margin-left:18px;margin-top:2px; float:left;color:#f15b6c;">'+val+'%</div><div style="margin-left: 6px;margin-top:6px; border:#f15b6c solid 1px; width:6px;height:6px; float:left;border-radius:3px; background-color:#f15b6c;" class="easyui-tooltip" title="30%<=value<70%" ></div>';
	            }else if(val>=70 && val<=100){
	                return '<div style="margin-left:18px;margin-top:2px; float:left;color:#7fb80e;">'+val+'%</div><div style="margin-left: 6px;margin-top:6px; border:#7fb80e solid 1px; width:6px;height:6px; float:left;border-radius:3px; background-color:#7fb80e;" class="easyui-tooltip" title="value>=70%"></div>';
	            }
            }
            var data = [
                {"productid":"FI-SW","status":"P","itemid":"EST-1"},
	            {"productid":"RP-SN","status":"P","itemid":"EST-11"},
	            {"productid":"RP-SN","status":"P","itemid":"EST-12"},
	            {"productid":"RP-LI","status":"P","itemid":"EST-13"},
	        ];
	        
 $(function(){
             $('.slide-out-div').tabSlideOut({
                 tabHandle: '.handle',                              
                 pathToTabImage: 'gray/images/contact_tab.png',                 
                 imageHeight: '122px',                               
                 imageWidth: '40px',                                
                 tabLocation: 'left',                               
                 speed: 300,                                        
                 action: 'click',                                   
                 topPos: '200px',                                  
                 fixedPosition: false                               
             });
         });
         
 var data = [
			            {"productid":"2","productname":"Koi","unitcost":2.50,"status":"P","listprice":3.00,"itemid":"Air"},
			           
			            {"productid":"1","productname":"Rattlesnake","unitcost":3,"status":"P","listprice":5,"itemid":"Hotel"},
			            
			            {"productid":"3","productname":"Iguana","unitcost":5,"status":"N","listprice":7,"itemid":"Car"},
			            {"productid":"5.5","productname":"Manx","unitcost":3.75,"status":"P","listprice":2,"itemid":"Rail"},
			            
			        ];   
			        $(function(){
			            var dg = $('#dg').datagrid();
			            dg.datagrid('enableFilter', [{
			                field:'listprice',
			                type:'numberbox',
			                options:{precision:1},
			                op:['equal','notequal','less','greater']
			            },{
			                field:'unitcost',
			                type:'numberbox',
			                options:{precision:1},
			                op:['equal','notequal','less','greater']
			            },{
			                field:'status',
			                type:'combobox',
			                options:{
			                    panelHeight:'auto',
			                    data:[{value:'',text:'All'},{value:'P',text:'P'},{value:'N',text:'N'}],
			                    onChange:function(value){
			                        if (value == ''){
			                            dg.datagrid('removeFilterRule', 'status');
			                        } else {
			                            dg.datagrid('addFilterRule', {
			                                field: 'status',
			                                op: 'equal',
			                                value: value
			                            });
			                        }
			                        dg.datagrid('doFilter');
			                    }
			                }
			            }]);
			        });